package com.lyl.security.common.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONUtil;

import javax.servlet.http.HttpServletResponse;

public class ServletUtils {

    public static final String JSON_CONTENT_TYPE = "application/json;charset=UTF-8";
    public static final String TEXT_CONTENT_TYPE = "text/plain;charset=UTF-8";

    public static void write(HttpServletResponse response, Object obj) {
        ServletUtil.write(response, JSONUtil.toJsonStr(obj), JSON_CONTENT_TYPE);
    }

    public static void writeToStr(HttpServletResponse response, Object obj) {
        ServletUtil.write(response, ObjectUtil.toString(obj), TEXT_CONTENT_TYPE);
    }
}
